//
//  SystemNotificatioanTableViewCell.m
//  HAODE
//
//  Created by LiYinDi on 15/12/30.
//  Copyright © 2015年 reabam.com. All rights reserved.
//

#import "SystemNotificatioanTableViewCell.h"
@implementation SystemNotificatioanTableViewCell

- (void)awakeFromNib {
    // Initialization code
   
    [self setAutoLayout];
}
-(void)setModel:(SystemNotificationModel *)model
{
//    NSString *str=model.messageContent;
    _messageContentLabel.text=[NSString stringWithFormat:@"%@",model.messageContent];
    _label.text=[NSString stringWithFormat:@"%@",model.messageContent];
       NSString *timeStr=model.messageTime;
        NSString *curStr=[self GetCurTime];
        double interval=[self GetStringTimeDiff:timeStr timeE:curStr];
        int hour=interval/3600;
        int minute=(int)interval % 3600 / 60;
        int day=(int)interval/3600/24;
        //    NSLog(@"curStr==%@,leftTimeStr===%@",curStr,leftTimeStr);
        //    NSLog(@"%f",interval);
        //    NSLog(@"hour===%d,minute=%d,day==%d",hour,minute,day);
        if (day!=0&&day>0) {
            self.timeLabel.text=[NSString stringWithFormat:@"%d天前",day];
        }
        else if((day==0||day<0)&&hour>0)
        {
            self.timeLabel.text=[NSString stringWithFormat:@"%d小时前",hour];
        }
        else if ((day<=0&&hour<=0)&&minute>=0) {
           self.timeLabel.text=[NSString stringWithFormat:@"%d分前",minute];
        }
        
   
}
- (double)GetStringTimeDiff:(NSString*)timeS timeE:(NSString*)timeE

{
    
    double timeDiff = 0.0;
    
    NSDateFormatter *formatters = [[NSDateFormatter alloc] init];
    [formatters setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *dateS = [formatters dateFromString:timeS];
    
    
    
    NSDateFormatter *formatterE = [[NSDateFormatter alloc] init];
    [formatterE setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *dateE = [formatterE dateFromString:timeE];
    
    
    timeDiff = [dateE timeIntervalSinceDate:dateS ];
    
    return timeDiff;
    
}

- (NSString*)GetCurTime

{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString*timeString=[formatter stringFromDate: [NSDate date]];
    
    
    return timeString;
}


-(void)setAutoLayout
{
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(10);
        make.width.equalTo(@30);
        
        make.height.equalTo(@30);
        
        make.top.equalTo(self.mas_top).with.offset(24);
    }];
    [_notiTagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconImageView.mas_right) ;
        make.right.equalTo(self.mas_right).with.offset(10);
        
        make.height.equalTo(@21);
        
        make.centerY.equalTo(_iconImageView.mas_centerY) ;
    }];
    [_messageContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(23) ;
        make.right.equalTo(self.mas_right).with.offset(-10);
        
        make.bottom.equalTo(_timeLabel.mas_top).with.offset(-15);
        
        make.top.equalTo(_notiTagLabel.mas_bottom).with.offset(14) ;
    }];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(23);
        make.right.equalTo(self.mas_right);
        
        make.height.equalTo(@14);
        
        make.top.equalTo(_messageContentLabel.mas_bottom).with.offset(15) ;
    }];
    [_lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(10);
        make.right.equalTo(self.mas_right).with.offset(-10) ;
        
        make.height.equalTo(@1);
        
        make.bottom.equalTo(self.mas_bottom).with.offset(-1);
    }];

    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
